package cn.iocoder.devlop.module.annual.report.baseinfo.controller.app;

import cn.iocoder.devlop.framework.common.pojo.CommonResult;
import cn.iocoder.devlop.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.devlop.module.annual.report.baseinfo.controller.vo.*;
import cn.iocoder.devlop.module.annual.report.baseinfo.service.BaseinfoService;
import cn.iocoder.devlop.module.infra.util.ConfigUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

import static cn.iocoder.devlop.framework.common.pojo.CommonResult.success;
import static cn.iocoder.devlop.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

@Tag(name = "用户 APP - 年报基本信息表")
@RestController
@RequestMapping("/annual/report/baseinfo")
@Validated
public class AppBaseinfoController {

    @Resource
    private BaseinfoService baseinfoService;


    @PutMapping("/submit")
    @Operation(summary = "提交并公示")
    @OperateLog(type = EXPORT)
    public CommonResult<String> submit(@Valid @RequestBody BaseinfoVO BaseinfoBase) {
        baseinfoService.submit(BaseinfoBase);
        return success(ConfigUtils.getConfigByKey("submitSuccess"));
    }

    @GetMapping("/list")
    @Operation(summary = "获得年报完成度列表")
    public CommonResult<List<CompletionCheckVO>> getBaseinfoList(@RequestParam("regno") String regno,@RequestParam(name ="uniscid",required = false) String uniscid) {
        List<CompletionCheckVO> checkVOS = baseinfoService.getBaseinfoList(regno,uniscid);
        return success(checkVOS);
    }


    @GetMapping("/imp")
    @Operation(summary = "导入往年年报信息")
    public CommonResult<Map<String, Boolean>> impData(@RequestParam("regno") String regno, @RequestParam("impAncheyear") String impAncheyear, @RequestParam("targetAncheyear") String targetAncheyear, @RequestParam("enttype") String enttype) {
        return success(baseinfoService.impData(regno, impAncheyear, targetAncheyear, enttype));
    }

    @PutMapping("/update-baseinfo")
    @Operation(summary = "更新年报基本信息")
    public CommonResult<Boolean> updateBaseinfo(@Valid @RequestBody BaseinfoUpdateReqVO updateReqVO) {
        baseinfoService.updateBaseinfo(updateReqVO);
        return success(true);
    }


    @PutMapping("/update-empnum")
    @Operation(summary = "更新从业人数信息")
    public CommonResult<Boolean> updateEmpnum(@Valid @RequestBody EmpnumUpdateVO updateReqVO) {
        baseinfoService.updateEmpnum(updateReqVO);
        return success(true);
    }

    @PutMapping("/update-partybuilding")
    @Operation(summary = "更新党建信息")
    public CommonResult<Boolean> updatePartybuilding(@Valid @RequestBody PartybuildingUpdateVO updateReqVO) {
        baseinfoService.updatePartybuilding(updateReqVO);
        return success(true);
    }

    @PutMapping("/update-assetinfo")
    @Operation(summary = "更新资产信息")
    public CommonResult<Boolean> updateAssetinfo(@Valid @RequestBody AssetinfoUpdateVO updateReqVO) {
        baseinfoService.updateAssetinfo(updateReqVO);
        return success(true);
    }

    @GetMapping("/get-baseinfo")
    @Operation(summary = "获得年报基本信息")
    public CommonResult<BaseinfoUpdateReqVO> getBaseinfo(@RequestParam("regno") String regno, @RequestParam("ancheyear") String ancheyear) {
        return success(baseinfoService.getBaseinfoForApp(regno, ancheyear));
    }

    @GetMapping("/get-empnum")
    @Operation(summary = "获取从业人数信息")
    public CommonResult<EmpnumUpdateVO> getEmpnum(@RequestParam("regno") String regno, @RequestParam("ancheyear") String ancheyear) {
        return success(baseinfoService.getEmpnum(regno,ancheyear));
    }

    @GetMapping("/get-partybuilding")
    @Operation(summary = "获取党建信息")
    public CommonResult<PartybuildingUpdateVO> getPartybuilding(@RequestParam("regno") String regno, @RequestParam("ancheyear") String ancheyear) {
        return success(baseinfoService.getPartybuilding(regno,ancheyear));
    }

    @GetMapping("/get-assetinfo")
    @Operation(summary = "获取资产信息")
    public CommonResult<AssetinfoUpdateVO> getAssetinfo(@RequestParam("regno") String regno, @RequestParam("ancheyear") String ancheyear) {
        return success(baseinfoService.getAssetinfo(regno,ancheyear));
    }



}
